home *** CD-ROM | disk | FTP | other *** search
/ The Mac 13 / the-mac-13.iso / Shareware City / Demos / TextPak Demo / Extras / MediaSwitcher.k < prev    next >
Encoding:
Text File  |  1995-06-09  |  3.6 KB  |  152 lines  |  [TEXT/MPS ]

  1. --
  2. -- FILE:    Common Objects:MediaSwitcher.k
  3. --
  4. -- AUTHOR:    Dan Crow
  5. --
  6. -- DATE:    22/6/94
  7. --
  8. -- Classes and objects that are specific to the Story of Glass project
  9. -- For example, the named MEDIADISTRIBUTOR class
  10. --
  11. --     © 1994, 1995 Art of Memory Ltd.
  12. --     All Rights Reserved
  13. --
  14. -- This file is supplied as part of the TextPak demonstration. You are only
  15. -- entitled to use this software to understand how the demonstration works.
  16. -- You may not duplicate, modify, reproduce or distribute this software in
  17. -- any form. If you wish to purchase a licence to use this software, please
  18. -- contact Art of Memory Ltd.
  19. --
  20.  
  21. -- This is an inheritable class based on the standard
  22. -- framework MEDIADELEGATOR class, but that can switch
  23. -- the media it displays.
  24. -- This class should probably be moved into a Common
  25. -- Objects library. Perhaps StoryOfGlass?
  26. class SwitchableMediaDelegator is MEDIADELEGATOR;
  27.  
  28. has
  29.     MediaNumber;
  30.     
  31.     SwitchImageOrientation(newWidth, newHeight)
  32.         newWidth is? INTEGER;
  33.         newHeight is? INTEGER;
  34.     
  35.     do
  36.         --self.SizeTo(newWidth, newHeight);
  37.         self.Target.SizeTo(newWidth,newHeight);
  38.     end;
  39.     
  40.     SetImageLocation(newX, newY)
  41.         newX is? INTEGER;
  42.         newY is? INTEGER;
  43.     
  44.     do
  45.         --self.MoveTo(newX, newY);
  46.         self.target.MoveTo(newX,newY);
  47.     end;
  48.     
  49.     SwitchImageMedia(imageName,...)
  50.         imageName is? STRING;
  51.         
  52.     use
  53.         myMedia;
  54.         theMediaList;
  55.         mediaItem;
  56.         loopCount;
  57.         FoundObject;
  58.         listSize;
  59.         oldCount;
  60.         
  61.     do
  62.     
  63.         -- Switch media to display the named image
  64.         myMedia := self.Target;
  65.         
  66.         theMediaList := (MEDIA.Items @ 1).Items;
  67.         if self.MediaNumber=VOID then
  68.         
  69.             -- Search through the media list for the object that
  70.             -- holds the portrait image that we wish to switch
  71.             from
  72.                 loopCount   := 1;
  73.                 foundObject := 0;
  74.                 listSize    := #theMediaList;
  75.             until (foundObject > 0) or (loopCount > listSize) loop
  76.                 if (theMediaList @ loopCount).Target = myMedia then
  77.                     foundObject := loopCount;
  78.                 end;
  79.             step
  80.                 loopCount := loopCount + 1;
  81.             end;
  82.             self.MediaNumber := foundObject;
  83.         else
  84.             foundObject := self.MediaNumber;
  85.         end;
  86.             
  87.         if foundObject>0 then
  88.  
  89.             -- Set the boolean need flag on the target to false if it isn't
  90.             -- already false.
  91.             if myMedia.IsNeeded() then
  92.                 myMedia.UnNeed();
  93.             end;
  94.             
  95.             oldCount := myMedia.PrepareCount;
  96.             -- Force the prepare count to 0, by setting it to
  97.             -- 1 then calling Unprepare() on it.
  98.             if myMedia.PrepareCount>0 then
  99.                 myMedia.PrepareCount := 1;
  100.                 myMedia.UnPrepare();
  101.             end;
  102.             
  103.             -- We can now guarante that self.Target.PrepareCount=0
  104.             -- and self.Target.Needed=false and that there is no
  105.             -- data loaded into self.Target.
  106.             
  107.             -- Now set the need flag on self.Target
  108.             myMedia.Need();
  109.             
  110.             -- Now set the name of self.Target to point to the
  111.             -- new file
  112.             (theMediaList @ foundObject).Name := imageName;
  113.             
  114.             --if (#argument=2) then
  115.             --    mediaItem.OverrideRoot := (argument @ 2);
  116.             --end;
  117.             
  118.             -- Call Install on the media object to correctly update the name
  119.             -- of the Target object.
  120.             (MEDIA @ 1).Install();
  121.             
  122.             -- Make sure the Target object is invalidated, to force a redraw
  123.             myMedia.InvalidateAll();
  124.             
  125.             -- Load the data into the target object and set PrepareCount as appropriate
  126.             if myMedia.IsLoaded() then
  127.                 myMedia.UnLoadData();
  128.             end;
  129.             myMedia.LoadData();
  130.             myMedia.Loaded := true;
  131.             myMedia.PrepareCount := oldCount;    
  132.         end;
  133.     end;
  134.  
  135. end;
  136.  
  137.  
  138. class SwitchableMovieDelegator is SwitchableMediaDelegator;
  139.  
  140. has
  141.     SwitchImageMedia(imageName,...)
  142.         imageName is? STRING;
  143.  
  144.     do
  145.         self.SwitchableMediaDelegator:SwitchImageMedia(imageName,...);
  146.         
  147.         self.Target.InvalidateAll();
  148.         self.Target.computeFocus();
  149.         self.Target.InvalidateAll();
  150.     end;
  151. end;
  152.